var submitUrl="/apps/formful",queryParams="";"/password"===window.location.pathname&&(submitUrl="https://formful.app/api/submission",queryParams="shop=".concat(window.Shopify.shop)),"stefano-teststore.myshopify.com"===window.Shopify.shop&&(submitUrl="/apps/formful-dev"),"127.0.0.1:3001"===window.location.host&&(submitUrl=localStorage.getItem("submitUrl")||submitUrl,queryParams="shop=".concat(window.Shopify.shop)),"herculesapps-formful-staging.myshopify.com"===window.Shopify.shop&&(submitUrl="/apps/formful-staging");try{window.Formful&&(window.Formful.addListener=function(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent("on"+t,n)},window.Formful.bind=function(e,t){return function(){return e.apply(t,arguments)}},window.Formful.setSelectorByValue=function(e,t){for(var n=0,r=e.options.length;n0&&window.Formful.setSelectorByValue(this.provinceEl,e)},countryHandler:function(e){var t=this.countryEl.options[this.countryEl.selectedIndex],n=t.getAttribute("data-provinces"),r=JSON.parse(n);if(this.clearOptions(this.provinceEl),r&&0==r.length)this.provinceContainer.style.display="none";else{(t=document.createElement("option")).value="",t.innerHTML="",t.disabled=!0,t.selected=!0,this.provinceEl.appendChild(t);for(var o=0;o".concat(null==w?void 0:w[1],": ").concat(g,"")}}var S=c.innerHTML.replace("{{ form }}",u);c.innerHTML=S,c.classList.add("formful__show"),window.Formful.scrollToElement(c),o(a,l,0)}"hide_and_message"===d&&e.target.classList.add("formful__hide"),"message"===d&&(e.target.reset(),r(a,l,0))}})).catch((function(e){i(a),n(a,l)}))}function n(e,t){for(var n=e.querySelectorAll(".formful__error"),i=e.querySelectorAll(".step"),a=0,l=n;a0){var i=window.Formful[t].currentStepIndex-1;r(e,t,i),o(e,t,i),window.Formful.scrollToElement(n)}}));l&&l.addEventListener("click",(function(){var e=window.Formful.parent(l,"formful__form");if(!window.Formful.validateForm(e,i[window.Formful[t].currentStepIndex])&&window.Formful[t].currentStepIndex0?t:null}function handleReCaptchaToken(e){var t=document.querySelector(".formful__form #captchaToken");t instanceof HTMLInputElement&&(t.value=e)}function resetRecaptcha(){if(window.grecaptcha){window.grecaptcha.reset();var e=document.querySelector(".formful__form #captchaToken");e instanceof HTMLInputElement&&(e.value="")}}function initStateSelect(e){window.Formful&&window.Formful.CountryProvinceSelector&&new window.Formful.CountryProvinceSelector(e,"field-country","field-province",{hideElement:"province-wrapper"})}function initPhoneField(e){e.querySelectorAll(".formful__country-picker").forEach((function(t){var n=t.querySelector("select");t.addEventListener("change",(function(n){!function(n){var r,o=t.querySelector(".formful__country-flag-img");o&&o.remove();var i=document.createElement("img");i.src="https://cdn.shopify.com/static/images/flags/".concat(n.toLowerCase(),".svg"),i.alt=n,i.width=25,i.height=25,i.classList.add("formful__country-flag-img"),t.appendChild(i);var a=null===(r=window.Formful.countryDialCodes)||void 0===r?void 0:r.find((function(e){return e.code===n}));a&&(e.querySelector(".formful__input--phone").value=a.dial_code)}(n.target.value)}));var r=n.getAttribute("data-default");r&&n.options.length>0&&window.Formful.setSelectorByValue(n,r)}))}function initVerticalAlignInputs(){var e=document.querySelectorAll(".formful__upload");e&&0!==e.length&&e.forEach((function(e){if(e.classList.contains("formful__no-padding-y")){var t=window.getComputedStyle(e).getPropertyValue("height");e instanceof HTMLElement&&(e.style.lineHeight=t)}}))}function initConditions(e,t){var n,r,o,i,a,l,c=e.querySelectorAll(".formful__form .formful__field-wrapper"),u=null===(r=null===(n=window.Formful)||void 0===n?void 0:n[t])||void 0===r?void 0:r.ruleList,s=null===(i=null===(o=window.Formful)||void 0===o?void 0:o[t])||void 0===i?void 0:i.conditionList;(null==s?void 0:s.find((function(e){return e.locale})))&&(s=s.filter((function(e){return e.locale===window.Shopify.locale})));var d=null===(l=null===(a=window.Formful)||void 0===a?void 0:a[t])||void 0===l?void 0:l.conditionGroupList;if((null==d?void 0:d.find((function(e){return e.locale})))&&(d=d.filter((function(e){return e.locale===window.Shopify.locale}))),s){var f={};s.forEach((function(e){"rule"!==e.type&&(f[e.parentId]||(f[e.parentId]=[]),f[e.parentId].push(e))}));var m={};d&&d.forEach((function(e){e.parentId.includes("rule_")||(m[e.parentId]||(m[e.parentId]=[]),m[e.parentId].push(e))}));var p=[];d&&d.forEach((function(e){e.parentId.includes("rule_")||p.push(e.parentId)}));var v={};s.forEach((function(e){e.conditionGroupId&&(v[e.conditionGroupId]||(v[e.conditionGroupId]=[]),v[e.conditionGroupId].push(e))}));var h={};s.forEach((function(e){"logic"!==e.type&&(h[e.parentId]||(h[e.parentId]=[]),h[e.parentId].push(e))}));var y={};d&&d.forEach((function(e){e.parentId.includes("rule_")&&(y[e.parentId]||(y[e.parentId]=[]),y[e.parentId].push(e))}));var g=[];s.forEach((function(e){var t=e.conditionFieldId;g.includes(t)||g.push(t)})),function(){function t(){u&&u.length>0&&(u.forEach((function(t){var n=e.querySelector("#field-"+t.parentId);n&&n instanceof HTMLInputElement&&(n.value="")})),u.forEach((function(t){var o=y[t.id],i=[];if(o)i=n(o);else{var a=h[t.id];if(!a)return;i=r(a)}var l=e.querySelector("#field-"+t.parentId),c=!i.includes(!1),u=i.includes(!0);"and"===t.logicalOperator&&c&&l&&l instanceof HTMLInputElement&&(l.value=t.newValue),"or"===t.logicalOperator&&u&&l&&l instanceof HTMLInputElement&&(l.value=t.newValue)}))),c.forEach((function(e){if(e instanceof HTMLElement&&e.dataset.fieldId){var t=m[e.dataset.fieldId],o=[];if(t)o=n(t);else{var i=f[e.dataset.fieldId];if(!i)return;o=r(i)}var a=e.dataset.logicAction,l=e.dataset.logicOperator,c=!o.includes(!1),u=o.includes(!0);"show"===a&&(e.style.display="none"),c&&"and"===l?("show"===a&&(e.style.display=""),"hide"===a&&(e.style.display="none")):c||"and"!==l||("show"===a&&(e.style.display="none"),"hide"===a&&(e.style.display="")),u&&"or"===l?("show"===a&&(e.style.display=""),"hide"===a&&(e.style.display="none")):u||"or"!==l||("show"===a&&(e.style.display="none"),"hide"===a&&(e.style.display=""))}}))}function n(e){var t=[];return e.forEach((function(e){var n=v[e.id];if(n){var o=r(n);"and"===e.logicalOperator&&(o.includes(!1)?t.push(!1):t.push(!0)),"or"===e.logicalOperator&&(o.includes(!0)?t.push(!0):t.push(!1))}})),t}function r(t){var n=[];return t.forEach((function(t){var r=t.operator;if(t.conditionFieldId){var o=e.querySelector("[id='field-".concat(t.conditionFieldId,"']"));if(o){var i=void 0;if((o instanceof HTMLInputElement||o instanceof HTMLSelectElement||o instanceof HTMLTextAreaElement)&&(i=o?o.value:void 0),o.classList.contains("formful__radio-group")){if(!((o=o.querySelector(":checked"))instanceof HTMLInputElement))return;i=o?o.value:void 0}else if(o.classList.contains("formful__checkbox")){if(!(o instanceof HTMLInputElement))return;i=o.checked?o.value:void 0}else if(o.classList.contains("formful__checkbox-group")){var a=o.querySelectorAll(":checked");i=Array.from(a).map((function(e){return e.value}))}switch(r){case"equals":Array.isArray(i)?n.push(i.includes(t.value)):n.push(i===t.value);break;case"not_equals":Array.isArray(i)?n.push(!i.includes(t.value)):n.push(i!==t.value);break;case"is_empty":n.push(!i);break;case"is_not_empty":n.push(!!i);break;default:console.error("Invalid operator")}}}})),n}g.forEach((function(n){if(n){var r=e.querySelector("[id='field-".concat(n,"']"));r&&(r.addEventListener("change",(function(){t()})),r.addEventListener("input",(function(){t()})))}})),t()}()}}function isLocalStorageAccessible(){try{return localStorage.setItem("test","test"),localStorage.removeItem("test"),!0}catch(e){return!1}}function initRealTimeValidation(e){e.querySelectorAll("input[data-validation], select[data-validation], textarea[data-validation], input[required]:not([readonly]), select[required], textarea[required]").forEach((function(e){e instanceof HTMLInputElement&&("checkbox"===e.type||"radio"===e.type)?e.addEventListener("change",(function(){window.Formful.validateInput(e)})):(e.addEventListener("blur",(function(){window.Formful.validateInput(e)})),e.addEventListener("input",(function(){e.classList.contains("formful__input--error")&&window.Formful.validateInput(e)})))}))}function initAltchaWidget(e,t){var n=e.querySelector("altcha-widget");n&&(n.style.display="none",n.addEventListener("statechange",(function(e){var r=e.detail||{},o=r.state,i=r.payload;"verified"===o&&i&&(window.Formful[t].altchaPayload=i),"code"===o&&(n.style.display="block"),"unverified"===o&&(n.style.display="block")})))}